#
# Status of a Renew Transaction
#

package ILS::Transaction::Renew;

use warnings;
use strict;

use ILS;
use ILS::Transaction;

use C4::Circulation;
use C4::Members;

our @ISA = qw(ILS::Transaction);

my %fields = (
	      renewal_ok => 0,
	      );

sub new {
    my $class = shift;;
    my $self = $class->SUPER::new();
    my $element;

    foreach $element (keys %fields) {
	$self->{_permitted}->{$element} = $fields{$element};
    }

    @{$self}{keys %fields} = values %fields;

    return bless $self, $class;
}

sub do_renew {
	my $self = shift;
	my $borrower = my $borrower = GetMember( $self->{patron}->id, 'cardnumber');
	if (CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber})){
		my $datedue = AddIssue( $borrower, $self->{item}->id, undef, 0 );
		$self->{'due'} = $datedue;
		$self->ok(1);
		$self->renewal_ok(1);
	}
	else {
		$self->ok(0);
	}
	return $self;
}	
1;
